package com.qf.spring01.utils;

import org.apache.ibatis.io.Resources;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class MyFactory {
    private String propertieFileName;
    private Properties properties;

    public MyFactory() throws IOException {
        this.propertieFileName = "beans.properties";
        properties = new Properties();
        InputStream inputStream = Resources.getResourceAsStream(propertieFileName);
        properties.load(inputStream);
    }

    public MyFactory(String propertieFileName) throws IOException {
        this.propertieFileName = propertieFileName;
        properties = new Properties();
        InputStream inputStream = Resources.getResourceAsStream(propertieFileName);
        properties.load(inputStream);
    }

    public Object getBean(String beanname) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        String property = properties.getProperty(beanname);
        Class<?> aClass = Class.forName(property);
        Object o = aClass.newInstance();
        return o;
    }

}
